var tools = {
		
	   //对象属猪操作 
	   //[{"role_id":"246","role_name":"店铺操作人员","is_check":"0","checked":"false"},{"role_id":"226","role_name":"店铺管理人员","is_check":"0","checked":"false"},{"role_id":"245","role_name":"分公司操作人员","is_check":"0","checked":"false"},{"role_id":"65","role_name":"分公司管理人员","is_check":"0","checked":"false"},{"role_id":"1","role_name":"系统管理员","is_check":"0","checked":"false"},{"role_id":"247","role_name":"总公司管理人员","is_check":"0","checked":"false"}]	
	   //[]
		
		getQueryString : function(queryStringName) {
			var returnValue = "";
			var URLString = window.location.href;
			var serachLocation = -1;
			var queryStringLength = queryStringName.length;
			do {
				serachLocation = URLString.indexOf(queryStringName + "\=");
				if (serachLocation != -1) {
					if ((URLString.charAt(serachLocation - 1) == '?')
							|| (URLString.charAt(serachLocation - 1) == '&')) {
						URLString = URLString.substr(serachLocation);
						break;
					}
					URLString = URLString.substr(serachLocation + queryStringLength
							+ 1);
				}

			} while (serachLocation != -1)
			if (serachLocation != -1) {
				var seperatorLocation = URLString.indexOf("&");
				if (seperatorLocation == -1) {
					returnValue = URLString.substr(queryStringLength + 1);
				} else {
					returnValue = URLString.substring(queryStringLength + 1,
							seperatorLocation);
				}
			}
			returnValue=decodeURIComponent(returnValue);
		
			return returnValue;
		},
		getRootPath: function(){
			 var curWwwPath = window.document.location.href;
	         var pathName = window.document.location.pathname;
	         var pos = curWwwPath.indexOf(pathName);
	         var localhostPath = curWwwPath.substring(0, pos);
	         var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
	         return (localhostPath + projectName)+"/";
		},
		insertArr: function(arr,obj,index){
			if(arr instanceof Array){
				arr.splice(index,0,obj);
				return arr;
			}else{
				console.log(arr+" 不为数组");
				return [];
			}			
		},
		
		insertLastArr: function(arr,obj){
			if(arr instanceof Array){
				arr.push(obj);
				return arr;
			}else{
				console.log(arr+" 不为数组");
				return [];
			}			
		},
		
		deleteArr: function(arr,index){
			if(arr instanceof Array){
				arr.splice(index,1);
				return arr;
			}else{
				console.log(arr+" 不为数组");
				return [];
			}				
			
		},		
		
		deleteLastArr:function(arr){
			if(arr instanceof Array){
				arr.pop();
				return arr;
			}else{
				console.log(arr+" 不为数组");
				return [];
			}				
		},
		
		deleteKeyArr: function(arr,key,keyValue){
			if(arr instanceof Array){
				for(var i=0;i<arr.length;i++){
					if(arr[i][key]==keyValue){
						arr.splice(i,1);
					}
				}
				return arr;				
			}else{
				console.log(arr+" 不为数组");
				return [];
			}				
		},		
		
		findArr: function(arr,key,keyValue){
			var idx = -1;
			if(arr instanceof Array){
				for(var i=0;i<arr.length;i++){
					if(arr[i][key]==keyValue){
						idx=i;
						break;
					}
				}  				
				return idx;							
			}else{
				console.log(arr+" 不为数组");
				return -3;
			}				
			
		},
		/**
		 * 根据关键字返回当前对象
		 */
		findArrToObj: function(arr,key,keyValue){
			var obj={};
			if(arr instanceof Array){
				for(var i=0;i<arr.length;i++){
					if(arr[i][key]==keyValue){
						obj=arr[i];
						break;
					}
				}  
				
				return obj;							
			}else{
				
				return obj;
			}				
			
		},
		
		/**
		 * arr 原始数组对象
		 * key 属性
		 * keyValuesStrs 属性多值 ","分隔
		 */
		getArr:function(arr,key,keyValueStrs)
		{
			var arrNew=[];
			var arrkeyValue=this.strToArr(keyValueStrs,",");
			for(var i=0;i<arrkeyValue.length;i++)
			{
				
				var obj=this.findArrToObj(arr,key,arrkeyValue[i]);
				if(JSON.stringify(obj) != "{}")
                {
					arrNew.push(obj);
                }				
			
			
			}
		  return arrNew;			
			
			
		},
		
		
		/**
		 * arr 原始数组对象
		 * key 属性
		 * keyValueArr
		 */
		getArr2:function(arr,key,keyValueArr)
		{
			var arrNew=[];
		
			for(var i=0;i<keyValueArr.length;i++)
			{
				
				var obj=this.findArrToObj(arr,key,keyValueArr[i]);
				if(JSON.stringify(obj) != "{}")
                {
					arrNew.push(obj);
                }				
			
			
			}
		  return arrNew;			
			
			
		},
		//字符串转数组
		strToSub:function(str,dot)
		{
			if(str==""||str=="null"||str=="undefined")
			{
				return str;
			}
			else
			{
				
				
				if(str.indexOf(dot)==0)
                {
					str=str.substr(1,str.length-1);
                }	
				
				if(str.lastIndexOf(dot)==str.length-1)
                {
					str=str.substr(0,str.length-1);
                }	
				
				
				return str;
				
				
			}
			
			
		
		},	
		
		
    //字符串转数组
	strToArr:function(str,dot)
	{
		if(str==""||str=="null"||str=="undefined")
		{
			return [];
		}
		else
		{
			return str.split(dot);
		}
		
		
	
	},
	
	//数组转字符串
	arrToStr:function(arr,dot)
	{
		if(Array.isArray(arr))
        {

			return arr.join(dot);
        }
		else
		{
			return "";
		}
		
		
		
	},

	ajaxRequest : function(actionName, reqData) {
		var repData = "";
		var type = (arguments[2] == null ? "" : arguments[2]);
		var that=this;
		if (type == "text") {
			$.ajax({
				type : "post",
				url : actionName,
				async : false,
				data : JSON.stringify(reqData),
				dataType : "text",
				contentType : "text/html",
				beforeSend : function() {
					if($("#loadDiv").length)
						that.showloading("loadDiv");
				},
				success : function(data) {
					if(data.respCode=="-999"){
						alert(data.respDesc).then(function (){
							top.location.href=that.getRootPath()+"/index.jsp";  							
						})	
//						return false;
						throw "not login";
					}
					repData = JSON.parse(data);
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				},
				error : function(err) {
					console.log(err);
					var jsonStr = {};
					// 获取token
					jsonStr.respCode = "9999";
					jsonStr.respDesp = "系统繁忙";
					// repData=JSON.parse(jsonStr);
					repData = jsonStr;
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				}
			});

		} else {
			$.ajax({
				type : "post",
				url : actionName,
				async : false,
				dataType : "json",
				data : reqData,
				beforeSend : function() {
					if($("#loadDiv").length)
						that.showloading("loadDiv");
				},
				success : function(data) {
					if(data.respCode=="-999"){
						alert(data.respDesc).then(function (){
							top.location.href=that.getRootPath()+"/index.jsp";  							
						})	
//						return false;
						throw "not login";
					}
					repData = data;
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				},
				error : function(err) {
					console.log(err);
					var jsonStr = {};
					// 获取token
					jsonStr.respCode = "9999";
					jsonStr.respDesp = "系统繁忙";
					// repData=JSON.parse(jsonStr);
					repData = jsonStr;
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				}
			});
		}
		return repData;
	},
	ajaxRequestAsync:function(actionName,reqData,cb)
	{	
		var that=this;
		var type= (arguments[3]==null?"":arguments[3]);
		if(type=="text"){
			$.ajax({
				type : "post",
				url : actionName,
				async : true,
				data : JSON.stringify(reqData),
			    dataType : "text",
				contentType: "text/html",
				beforeSend : function() {
					if($("#loadDiv").length)
						that.showloading("loadDiv");
				},
				success : function(data) {
					if(data.respCode=="-999"){
						alert(data.respDesc).then(function (){
							top.location.href=that.getRootPath()+"/index.jsp";  							
						})	
//						return false;
						throw "not login";
					}
					cb(JSON.parse(data));				
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				},
				error : function(err) {
						 var jsonStr = {};
							//获取token						
						 jsonStr.respCode = "9999";
						 jsonStr.respDesp = "系统繁忙";						
						 cb(jsonStr);							
						 if($("#loadDiv").length)
							that.closeloading("loadDiv");
				}
			});
			
			
		}else{
			$.ajax({
				type : "post",
				url : actionName,
				async : true,
				dataType : "json",
				data : reqData,
				beforeSend : function() {
				
					if($("#loadDiv").length)
						that.showloading("loadDiv");
					
				},
				success : function(data) {
					if(data.respCode=="-999"){
						alert(data.respDesc).then(function (){
							top.location.href=that.getRootPath()+"/index.jsp";  							
						})	
//						return false;
						throw "not login";
					}
					cb(data);					
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				},
				error : function(err) {
					 var jsonStr = {};
						//获取token						
					 jsonStr.respCode = "9999";
					 jsonStr.respDesp = "系统繁忙";				
					 cb(jsonStr);						
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				}
			});
		}
	},	
	
	
	ajaxRequestEx : function(actionName, reqData) {
		var repData = "";
		var type = (arguments[2] == null ? "" : arguments[2]);
		var that=this;
		if (type == "text") {
			$.ajax({
				type : "post",
				url : config.domain!=""?config.domain+actionName:that.getRootPath()+actionName,
				async : false,
				data : JSON.stringify(reqData),
				dataType : "text",
				contentType : "text/html",
				beforeSend : function() {
					if($("#loadDiv").length)
						that.showloading("loadDiv");
				},
				success : function(data) {
					repData = JSON.parse(data);
					if(data.respCode=="-999"){
						alert(data.respDesc).then(function (){
							top.location.href=that.getRootPath()+"/index.jsp";  							
						})	
//						return false;
						throw "not login";
					}
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				},
				error : function(err) {
					console.log(err);
					var jsonStr = {};
					// 获取token
					jsonStr.respCode = "9999";
					jsonStr.respDesp = "系统繁忙";
					// repData=JSON.parse(jsonStr);
					repData = jsonStr;
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				}
			});

		} else {
			$.ajax({
				type : "post",
				url : config.domain!=""?config.domain+actionName:that.getRootPath()+actionName,
				async : false,
				dataType : "json",
				data : reqData,
				beforeSend : function() {
					if($("#loadDiv").length)
						that.showloading("loadDiv");
				},
				success : function(data) {
					repData = data;
					if(data.respCode=="-999"){
						alert(data.respDesc).then(function (){
							top.location.href=that.getRootPath()+"/index.jsp";  							
						})	
//						return false;
						throw "not login";
					}
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				},
				error : function(err) {
					console.log(err);
					var jsonStr = {};
					// 获取token
					jsonStr.respCode = "9999";
					jsonStr.respDesp = "系统繁忙";
					// repData=JSON.parse(jsonStr);
					repData = jsonStr;
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				}
			});
		}
		return repData;
	},
	
	
	
	ajaxRequestAsyncEx:function(actionName,reqData,cb)
	{	
		var that=this;
		var type= (arguments[3]==null?"":arguments[3]);
		if(type=="text"){
			$.ajax({
				type : "post",
				url : config.domain!=""?config.domain+actionName:that.getRootPath()+actionName,
				async : true,
				data : JSON.stringify(reqData),
			    dataType : "text",
				contentType: "text/html",
				beforeSend : function() {
					if($("#loadDiv").length)
						that.showloading("loadDiv");
				},
				success : function(data) {
					if(data.respCode=="-999"){
						alert(data.respDesc).then(function (){
							top.location.href=that.getRootPath()+"/index.jsp";  							
						})	
//						return false;
						throw "not login";
					}
					cb(JSON.parse(data));				
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				},
				error : function(err) {
						 var jsonStr = {};
							//获取token						
						 jsonStr.respCode = "9999";
						 jsonStr.respDesp = "系统繁忙";						
						 cb(jsonStr);							
						 if($("#loadDiv").length)
							that.closeloading("loadDiv");
				}
			});
			
			
		}else{
			$.ajax({
				type : "post",
				url : config.domain!=""?config.domain+actionName:that.getRootPath()+actionName,
				async : true,
				dataType : "json",
				data : reqData,
				beforeSend : function() {
				
					if($("#loadDiv").length)
						that.showloading("loadDiv");
					
				},
				success : function(data) {
					if(data.respCode=="-999"){
						alert(data.respDesc).then(function (){
							top.location.href=that.getRootPath()+"/index.jsp";  							
						})	
//						return false;
						throw "not login";
					}
					cb(data);					
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				},
				error : function(err) {
					 var jsonStr = {};
						//获取token						
					 jsonStr.respCode = "9999";
					 jsonStr.respDesp = "系统繁忙";				
					 cb(jsonStr);						
					if($("#loadDiv").length)
						that.closeloading("loadDiv");
				}
			});
		}
	},	
	
//	getRootPath: function(){
//		 var curWwwPath = window.document.location.href;
//        var pathName = window.document.location.pathname;
//        var pos = curWwwPath.indexOf(pathName);
//        var localhostPath = curWwwPath.substring(0, pos);
//        var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
//        return (localhostPath + projectName);
//	},
	loadDiv: function(){
		var img = this.getRootPath()+"plugin/images/loading.gif";
		var div = "<div id='BgDiv' style='display:none;'></div>" +
		"<div id='loadDiv' style='display:none'>" +
		"<img src='"+img+"'/>"+
		"</div>";
		if($(".panel-default").length){
			$(".panel-default").append(div);
		}
		else{
			$("body").append(div);
		}
	},	
	
	
	
	loadModal: function(type,id,btn){
		var str = "<div class='modal fade' id='"+type+"modal' tabindex='-1' role='dialog'"+
					"aria-labelledby='"+type+"modalLabel' aria-hidden='true'>"+
					"<div class='modal-dialog modal-sm'>"+
						"<div class='modal-content'>"+
							"<input type='hidden' id='"+id+"'>"+
							"<div class='modal-header'>"+
								"<button type='button' class='close' data-dismiss='modal'>"+
									"<span aria-hidden='true'>&times;</span> <span class='sr-only'>Close</span>"+
								"</button>"+
								"<h5 class='modal-title' id='"+type+"modalLabel'>提示信息</h5>"+
							"</div>"+
							"<div class='modal-body'>"+
								"<div class='alert alert-warning' id='"+type+"Msgdiv' role='alert'></div>"+
								"<div class='alert alert-danger' id='"+type+"MsgErrdiv' role='alert'></div>"+
							"</div>" +
							"<div class='modal-footer'>"+
								"<button type='button' class='btn btn-default' data-dismiss='modal'>取消</button>"+
								"<button type='button' class='btn btn-primary' id='"+btn+"'"+
									"data-loading-text='请稍候...'>确定</button>"+
							"</div>" +
						"</div>"+
					"</div>"+
				"</div>";
		
		if($(".panel-default").length){
			$(".panel-default").append(str);
		}
		else{
			$("body").append(str);
		}		
	},
	
	showloading:function(objid){	

		$("#BgDiv").css({
			display : "block",
			height : $(document).height()
		});
		$("#" + objid).css("display", "block");
		//document.documentElement.scrollTop = 0;
		//document.documentElement.scrollIntoView

	},
	
	closeloading:function(objid) {
		$("#BgDiv").css("display", "none");
		$("#" + objid).css("display", "none");
	},
	
	getConfig:function(arg){
		// arg.prop arg.config(可选)
		var result = null;
		var data = tools.ajaxRequest(user.getAppRoot()+"/pub/common/getConfig", arg);
		if(data.respCode=="0"){
			result = data.value;
		}else{
			console.log(data.respDesc);
		}
		return result;				
	},
	JSONToExcelConvertor: function(fileName, jsonData) { ///<summary>json转excel下载</summary> ///<param name="fileName">文件名</param> ///<param name="jsonData">数据</param>        //json var arrData = typeof jsonData != 'object' ? JSON.parse(jsonData) : jsonData; // #region 拼接数据 var excel = '<table>'; //设置表头 var row = "<tr>"; for (var name in arrData[0]) { //每个单元格都可以指定样式. eg color:red   生成出来的就是 红色的字体了. row += "<td style='color:red;text-align:center;'>" + name + '</td>'; } //列头结束 excel += row + "</tr>"; //设置数据 for (var i = 0; i < arrData.length; i++) { var row = "<tr>"; for (var index in arrData[i]) { var value = arrData[i][index] === "." ? "" : arrData[i][index]; row += '<td style="text-align:center;">' + value + '</td>';//将值放入td } //将td 放入tr,将tr放入table excel += row + "</tr>"; } //table结束 excel += "</table>"; // #endregion // #region 拼接html var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>"; excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">'; excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel'; excelFile += '; charset=UTF-8">'; excelFile += "<head>"; excelFile += "<!--[if gte mso 9]>"; excelFile += "<xml>"; excelFile += "<x:ExcelWorkbook>"; excelFile += "<x:ExcelWorksheets>"; excelFile += "<x:ExcelWorksheet>"; excelFile += "<x:Name>"; excelFile += "{worksheet}"; excelFile += "</x:Name>"; excelFile += "<x:WorksheetOptions>"; excelFile += "<x:DisplayGridlines/>"; excelFile += "</x:WorksheetOptions>"; excelFile += "</x:ExcelWorksheet>"; excelFile += "</x:ExcelWorksheets>"; excelFile += "</x:ExcelWorkbook>"; excelFile += "</xml>"; excelFile += "<![endif]-->"; excelFile += "</head>"; excelFile += "<body>"; excelFile += excel;//将table 拼接 excelFile += "</body>"; excelFile += "</html>"; // #endregion var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile); //创建a标签 var link = document.createElement("a"); //指定url link.href = uri; //设置为隐藏 link.style = "visibility:hidden"; //指定文件名和文件后缀格式 link.download = fileName + ".xls"; //追加a标签 document.body.appendChild(link); //触发点击事件 link.click(); //移除a标签 document.body.removeChild(link); }
		var arrData = typeof jsonData != 'object' ? JSON.parse(jsonData) : jsonData; // #region 拼接数据 
		var excel = '<table>'; //设置表头 
		var row = "<tr>"; 
		for (var name in arrData[0]) { //每个单元格都可以指定样式. eg color:red   生成出来的就是 红色的字体了. 
			row += "<td style='color:red;text-align:center;'>" + name + '</td>'; 
		} //列头结束 
		excel += row + "</tr>";
		for (var i = 0; i < arrData.length; i++) {
			 var row = "<tr>";
			 for (var index in arrData[i]) {
				 var value = arrData[i][index] === "." ? "" : arrData[i][index];
				 row += '<td style="text-align:center;">' + value + '</td>';//将值放入td
			 }
			 excel += row + "</tr>";
		}
		excel += "</table>";
		var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>"
		excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
		excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
		excelFile += '; charset=UTF-8">';
		excelFile += "<head>";
		excelFile += "<!--[if gte mso 9]>";
		excelFile += "<xml>";
		excelFile += "<x:ExcelWorkbook>";
		excelFile += "<x:ExcelWorksheets>";
		excelFile += "<x:ExcelWorksheet>";
		excelFile += "<x:Name>";
		excelFile += "{worksheet}";
		excelFile += "</x:Name>";
		excelFile += "<x:WorksheetOptions>";
	    excelFile += "<x:DisplayGridlines/>";
	    excelFile += "</x:WorksheetOptions>";
        excelFile += "</x:ExcelWorksheet>";
        excelFile += "</x:ExcelWorksheets>";
        excelFile += "</x:ExcelWorkbook>";
        excelFile += "</xml>";
        excelFile += "<![endif]-->";
        excelFile += "</head>"; excelFile += "<body>"; 
        excelFile += excel;//将table 拼接 
        excelFile += "</body>"; 
        excelFile += "</html>";
        var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
        var link = document.createElement("a");
        link.href = uri;
        link.style = "visibility:hidden";
        link.download = fileName + ".xls";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
	},
	checkPriv:function(privs,privName){
		 if(privs.indexOf(privName)<0)
         {
         	alert("您没有操作权限,请联系管理员!");            
         	window.close();
         }				
	},
	
	jsonsort:function(arr,sortOption){
//		 let list = [
//		             {"user_id":"101744","real_name":"要闻部主任","dept_code":"1","dept_code_name":"要闻部","group_code":"0","group_code_name":"无","duty_flag":"4"},
//		             {"user_id":"100003","real_name":"王颖","dept_code":"1","dept_code_name":"要闻部","group_code":"0","group_code_name":"无","duty_flag":"2"},
//		             {"user_id":"101703","real_name":"孔祥楠","dept_code":"1","dept_code_name":"要闻部","group_code":"1","group_code_name":"无","duty_flag":"1"},
//		             {"user_id":"101663","real_name":"陈欣","dept_code":"1","dept_code_name":"要闻部","group_code":"2","group_code_name":"无","duty_flag":"1"},
//		             {"user_id":"101643","real_name":"常伟明","dept_code":"1","dept_code_name":"要闻部","group_code":"0","group_code_name":"无","duty_flag":"5"}
//		             ]
	      let sortjson = (arr, sortOption)=> {
	          // console.log(Object.keys(sortOption))
	          let opts = Object.keys(sortOption).map((k)=>{
	            return {
	              name: k,
	              dir: sortOption[k]
	            }
	          })
	          // console.log(opts)
	          arr.sort((s1, s2)=> {            
	            let count = 0;
	            let fun = (a, b, op)=> {
	              let r = op.dir == "asc" ? 1 : -1;
	              let name = op.name;
	              if(a[name] < b[name]){
	                return -1 * r;
	              }
	              else if(a[name] > b[name]){
	                return 1 * r;
	              }
	              else {
	                count++;
	                if(opts[count]){
	                  return fun(a, b, opts[count])
	                }
	                return 0;
	              }
	            }
	            return fun(s1, s2, opts[count])            
	          });
	        }
	      sortjson(arr,sortOption );
	      return arr;
//		      sortjson(list,{"duty_flag":"desc","group_code": "asc","real_name":"asc"} )
//		             console.log(list)		
	},
	
	getsonToParent:function(value,depts){
		var arry = [];
		if(depts.length>0){
			depts.forEach(function(item,index){
				if(item.id==value){
					arry.push(value);
				}else if(item.children!=undefined&&item.children!=null&&item.children.length>0){
					item.children.forEach(function(obj,idx){
						if(obj.id==value){
							arry.push(item.id);
							arry.push(obj.id);
						}else if(obj.children!=undefined&&obj.children!=null&&obj.children.length>0){
							obj.children.forEach(function(o,i){
								if(o.id==value){
									arry.push(item.id);
									arry.push(obj.id);
									arry.push(o.id);
								}
							});
						}						
					});					
				}				
			});
		}
		return arry;
	},
	
	getChilds:function(arry,depts){
		var that =this;
		if(depts.length>0){
			depts.forEach(function(item,index){
				if(item.children!=undefined&&item.children!=null&&item.children.length>0){
					that.getChilds(arry,item.children);
				}else{
					arry.push(item.id);
				}
			});
		}
		return arry;
	},
	
	hasChild:function(id,depts){
		var that=this;
		var has = false;
		if(depts.length>0){
			for(var i=0;i<depts.length;i++){
				if(depts[i].id==id){
					if(depts[i].children!=undefined&&depts[i].children!=null&&depts[i].children.length>0){
						has = true;
						break;
					}
				}else if(depts[i].children!=undefined&&depts[i].children!=null&&depts[i].children.length>0){
					has = that.hasChild(id,depts[i].children);
				}					
			}					
		}				
		return has;
	},
	
	arrToStrParam:function(arry,arg){
		var result = arry.map(function(item){
			if(arg==0){
				return "'"+item+"'";
			}else{
				return item;
			}
		});
		return result.join(",");
	},
	
	getCDepts:function(deptId,rankflag){
		var cascaderdept={};
		var depts;    	
    	var reqData = {
				"id" : deptId,
				"removeChild" : "removeChild",
				"showAll" : "1",    //showAll 1 显示完整的部门结构数据  如三层结构， 如果有的部门是二层，还没加三层，是不实现该部门的  
			          };
    	if(rankflag==="0")
    	{
    		url="../../dept/deptTreeEx";
    	}
    	else
    	{
    		url="../../dept/deptTreeEx2";
    	}
    	
		data = tools.ajaxRequest(url,reqData);   
		
        if(data[0].deptLevel=="1")
        {
        	depts=data[0].children;
        }
        else
        {
        	depts=data;
        }		
		  	   	
    	cascaderdept.deptvalue= [];
    	cascaderdept.depts=depts;
//    	cascaderdept.depts=depts.map(function(item){
//    		if(item.children.length==0){
//    			delete item["children"];
//    		}
//    		return item;
//    	});
    	return cascaderdept;
		
	},
	
	/*
	 * para1 deptdefault 部门默认值 编辑 或者初始化 部门id
	 * para2 deptId  部门遍历起点  rankFlag为 0 起点可不写 
	 * para3 rankflag 0  根据人员查看部门权范围 获取部门  1 rank无关    
	 * 
	 */	 
	getDeptOpts:function(deptdefault,deptId,rankflag){
    	var cascaderdept={};
		var depts;    	
    	var reqData = {
				"id" : deptId,
				"removeChild" : "removeChild",
				"showAll" : "",    //showAll 1 显示完整的部门结构数据  如三层结构， 如果有的部门是二层，还没加三层，是不实现该部门的  
			          };
    	if(rankflag==="0")
    	{
    		url="../../pub/dept/deptTreeEx";
    	}
    	else
    	{
    		url="../../pub/dept/deptTreeEx2";
    	}
    	
		data = tools.ajaxRequest(url,reqData);   
		//console.log(JSON.stringify(data));
        if(data.tree[0].deptLevel=="1")
        {
        	depts=data.tree[0].children;
        }
        else
        {
        	depts=data.tree;
        }		
		  	   	
    	var deptvalue=tools.getsonToParent(deptdefault,depts);
    	cascaderdept.deptvalue= deptvalue+"";
    	cascaderdept.depts=depts;
//       	cascaderdept.depts=depts.map(function(item){
//   		 item.value=item.id;
//   		 return item;
//       	});
//    	cascaderdept.depts=depts.map(function(item){
//    		if(item.children.length==0){
//    			delete item["children"];
//    		}
//    		return item;
//    	});


    	
    	return cascaderdept;
    
    },
	
    deptchange:function(value,depts){    	
    	//alert(value);
    //	var value = this.cascaderdept.deptvalue;
    	var arry=[];
    	if(value.length==0){
    		//取全部
//    		arry = tools.getChilds(arry,depts);
    		arry.push("-1");
    	}else{
    		var v= value[value.length-1];
//    		arry = this.getDepts(v,arry,depts);
    		arry.push(v);
    	}
    	
		return arry;
		
    },
    
    getDepts:function(value,arry,depts){
    	var that =this;
    	depts.forEach(function(item,index){
    		if(item.id==value){
    			if(item.children!=undefined&&item.children!=null&&item.children.length>0){
    				var deptvalue = [];
    				deptvalue.push(item);
    				arry = tools.getChilds(arry,deptvalue);
    			}else{
    				arry.push(value);
    			}    			
    		}else if(item.children!=undefined&&item.children!=null&&item.children.length>0){
    			that.getDepts(value,arry,item.children);
    		}
    	});    	
    	return arry;
    },
    getshorten:function(txt,num){
    	if(txt.length>parseInt(num)){
    		return txt.substr(0,parseInt(num))+"...";
    	}
    	return txt;
    },
	getuuid : function(len, radix) {
		var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
				.split('');
		var uuid = [], i;
		radix = radix || chars.length;

		if (len) {
			// Compact form
			for (i = 0; i < len; i++)
				uuid[i] = chars[0 | Math.random() * radix];
		} else {
			// rfc4122, version 4 form
			var r;

			// rfc4122 requires these characters
			uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
			uuid[14] = '4';

			// Fill in random data. At i==19 set the high bits of clock sequence
			// as
			// per rfc4122, sec. 4.1.5
			for (i = 0; i < 36; i++) {
				if (!uuid[i]) {
					r = 0 | Math.random() * 16;
					uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
				}
			}
		}

		return uuid.join('');
	},
	
	// 排序数字数组
	sortNArray:function(arr){
		var array = arr;
		array.sort(function(a,b){
			return a-b;
		});		
		return array;
	},
	
	ReplaceAll: function(str, sptr, sptr1){
        while (str.indexOf(sptr) >= 0){
           str = str.replace(sptr, sptr1);
        }
        return str;
	},
	
	RmvComma:function(str){
		var result = str;
		if(str.indexOf(",")==0&&str.lastIndexOf(",")==(str.length-1)){
			result = str.substr(1,str.length-2);
		}
		return result;
	},
	
	  timeoutAlert: function(txt, duration) {
        duration = duration || 3000;
        var myTime;            
        alert(txt).then(
          function(){
             clearTimeout(myTime);
        });                                
       myTime = setTimeout(function(){
          $(".el-message-box__wrapper button").click()},
      duration);        
     }
};
//$(function(){
	 tools.loadDiv();
	//alert(tools.getRootPath());
//});
